﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace BaoVeBienCuong.Store
{
    public class ButtonStore
    {
        private int Type;//0 là tướng, 1 là vật phẩm, 2 là lính, 3 là kĩ năng, 4 là nạp xu,5 là thoát
        private Vector2 position;
        private Vector2 size;
        private Texture2D image;
        private bool isSelect;
        private float scale = 2.0f / 3.0f;
        public ButtonStore()
        {
            Type = 0;
            position = new Vector2(0, 0);
            size = new Vector2(135, 94);
            isSelect = false;
        }
        public ButtonStore(int type)
        {
            Type = type;
            size = new Vector2(135, 94) * scale;
            position = new Vector2(Type * (size.X + 4) + 5, 6);
            if (Type == 5)
            {
                scale = 0.8f;
                size = new Vector2(87, 87) * scale;
                position = new Vector2(730, 5);
            }
            if (Type == 0) isSelect = true;
            else isSelect = false;
        }
        public void setType(int type)
        {
            Type = type;
            position = new Vector2(Type * 150 + 20, 20);
        }
        public void Load(ContentManager content)
        {
            if (Type < 4)
            {
                image = content.Load<Texture2D>("images/store/profileButton");
            }
            else if (Type == 5)
            {
                image = content.Load<Texture2D>("images/store/exit");
            }
            else
            {
                image = content.Load<Texture2D>("images/store/chargeMoney");
            }
        }
        public void Draw(SpriteBatch sprite)
        {
            if (Type == 5)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(0, 0, 87, 87), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(87, 0, 87, 87), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
            }
            else if (Type == 4 || Type == 3)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(0, 0, 135, 94), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(135, 0, 135, 94), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
            }
            else if (Type == 0)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(0, 94, 135, 94), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(135, 94, 135, 94), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
            }
            else if (Type == 1)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(270, 94, 135, 94), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(405, 94, 135, 94), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
            }
            else
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(270, 0, 135, 94), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(405, 0, 135, 94), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
            }
        }
        public bool isTouch(Vector2 posi)
        {
            if (posi.Y > (position.Y + size.Y))
            {
                return false;
            }
            else
            {
                if (posi.X > 470 && posi.X < 730)
                {
                    return false;
                }
                else
                {
                    isSelect = false;
                    if (posi.X >= position.X && posi.X <= (position.X + size.X) && posi.Y >= position.Y && posi.Y <= (position.Y + size.Y))
                    {
                        isSelect = true;
                        MainPage.PlayHieuUng("Click",false);
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
        }
        public void setTouch(bool x)
        {
            isSelect = x;
        }
    }
}
